<?php
/***************************************************************************
 *
 *   copyright            : (C) 2005 Winds of Storm
 *
 *   $Id: init.php,v 1.5 2007/01/30 21:02:43 nathan Exp $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

require("$libdir/db.$phpEx");
require("$libdir/constants.$phpEx");

if (isset($dbhost2)) {
	//
	// Make the database connection to board db; chat db is automatic.
	//
	$db2 = new sql_db($dbhost2, $dbuser2, $dbpasswd2, $dbname2, false);
	if(!$db2->db_connect_id) {
		die("Could not connect to the database $dbname2 @ $dbhost2");
	}
} else {
	$db2    = $db;
}

//
// Load config settings from the database
//
$sql	= "SELECT * FROM {$dbprefix}config";
$res	= $db->sql_query($sql);
while (($row = $db->sql_fetchrow($res))) {
	$config[$row['config_name']]	= $row['config_value'];
}

//
// Load forum-specific settings
//
require($libdir . $config['FORUM_TYPE'] . "_fal.$phpEx");

//
// Load other initial files
//
require("$libdir/security.$phpEx");
require("$libdir/template.$phpEx");
require("$libdir/header.$phpEx");

//
// Set default template if none selected and init TPL_ variables.
//
if ($config['TEMPLATE'] == '') {
	$config['TEMPLATE']	= 'default';
}
$config['TPL_DIR']	= realpath("$basedir/templates") . '/' . $config['TEMPLATE'] . '/';
$config['TPL_WWW']	= $config['CHAT_URL'] . "/templates/" . $config['TEMPLATE'] . "/";

//
// Load header unless directed to skip...
//
if (!$skip_header) {
	showHeader($body, $header);
}

